package com.coder.search.service;

import com.coder.search.dao.ArticleSearchDao;
import com.coder.search.pojo.Article;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import util.IdWorker;

/**
 * @BelongsProject:coder_parent
 * @BelongsPackage:com.coder.search.service
 * @Author:linchong
 * @CreateTime:2019-01-05 20:09
 * @Description:
 */
@Service
public class ArticleSearchService {

    @Autowired
    private ArticleSearchDao articleSearchDao;

//    @Autowired
//    private IdWorker idWorker;
    /**
     * 添加文章
     * @param article
     */
    public void add(Article article){
        //article.setId(idWorker.nextId()+"");
        articleSearchDao.save(article);
    }

    public Page<Article> findByTitleLike(String keywords, int page, int size){
        PageRequest pageRequest = PageRequest.of(page-1,size);
        return articleSearchDao.findByTitleOrContentLike(keywords,keywords,pageRequest);
    }
}









